package com.aabte.design.pattern.behavioral.memento;

public class Test {
    public static void main(String[] args) {

        ArticleMementoManager articleMementoManager = new ArticleMementoManager();
        Article article = new Article("Java手记v1", "Java手记v1内容", "Java手记v1图片");

        ArticleMemento javaArticleMementoV1 = article.saveToMemento();
        articleMementoManager.addMemento(javaArticleMementoV1);

        System.out.println("标题："+ article.getTitle()+"内容："+ article.getContent()+"图片："+ article.getImgs());
        System.out.println("手记完整信息："+article);

        System.out.println();

        System.out.println("修改手记 Start");
        article.setTitle("Python手记v2");
        article.setContent("Python手记v2内容");
        article.setImgs("Python手记v2图片");
        System.out.println("修改手记 End");

        ArticleMemento javaArticleMementoV2 = article.saveToMemento();
        articleMementoManager.addMemento(javaArticleMementoV2);

        System.out.println();

        System.out.println("修改手记 Start");
        article.setTitle("Python手记v3");
        article.setContent("Python手记v3内容");
        article.setImgs("Python手记v3图片");
        System.out.println("修改手记 End");

        ArticleMemento javaArticleMementoV3 = article.saveToMemento();
        articleMementoManager.addMemento(javaArticleMementoV3);

        System.out.println();

        System.out.println("暂存回退 Start");

        System.out.println("回退出栈1次");
        ArticleMemento mementov1 = articleMementoManager.getMemento();
        article.undoFromMemento(mementov1);
        System.out.println(article);

        System.out.println("回退出栈2次");
        ArticleMemento mementov2 = articleMementoManager.getMemento();
        article.undoFromMemento(mementov2);
        System.out.println(article);

        System.out.println("回退出栈3次");
        ArticleMemento mementov3 = articleMementoManager.getMemento();
        article.undoFromMemento(mementov3);
        System.out.println(article);
        System.out.println("暂存回退 End");

    }
}
